package com.meihua.baoleyi.ui;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.meihua.baoleyi.R;
import com.meihua.baoleyi.base.RegBaseActivity;
import com.meihua.baoleyi.utils.LmsConstant;
import com.meihua.baoleyi.utils.SharedPreUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
 * Author:liming
 * Time: 2017/10/17
 * 重设密码
 */

public class ResetPayPwdActivity extends RegBaseActivity {
    @Bind(R.id.show_hao)
    EditText showHao;
    @Bind(R.id.find_paywpd_submit)
    Button findPaywpdSubmit;
    @Bind(R.id.show_name)
    TextView tvShowName;
    String name;
    Toast toast;
    @Bind(R.id.text_back)
    ImageView textBack;
    @Bind(R.id.text_title)
    TextView textTitle;
    @Override
    public int getLayoutResource() {
        return R.layout.activity_find_pay_pwd;
    }

    @Override
    public void onInitView() {
        ButterKnife.bind(this);
        textTitle.setText("验证身份");
        name = SharedPreUtils.getString(LmsConstant.REAL_NAME,"",this);
        if(name !=null && name.length() > 2){
            name = name.replace(name.substring(0, name.length() - 2), "**");
        }
        tvShowName.setText(name);
    }
    @OnClick({R.id.text_back, R.id.find_paywpd_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.text_back:
                finish();
                break;
            case R.id.find_paywpd_submit:
                submit();
                break;
        }
    }
    public void showShortCenter(Context context, String content) {

        if (toast == null) {
            toast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
        } else {
            toast.setText(content);
            toast.setGravity(Gravity.CENTER, 0, 0);
        }
        toast.show();
    }
    private void submit() {
        if (showHao.getText() == null || TextUtils.isEmpty(showHao.getText()) || TextUtils.isEmpty(showHao.getText().toString().trim())) {
            Toast.makeText(this, "请输入您的身份证号", Toast.LENGTH_SHORT).show();
            return;
        }
        Pattern pattern = Pattern.compile("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$");
        Matcher matcher = pattern.matcher(showHao.getText().toString().trim());
        if (!matcher.matches()) {
            Toast.makeText(this, "您输入的身份证号格式不正确", Toast.LENGTH_SHORT).show();
            return;
        }
//        OkGo.post(UrlContants.REST_PAY_PWD_VERIFY_CARD)
//                .tag(this)
//                .params("user_id", SharedPreUtils.getString(LmsConstant.USER_ID, "", ResetPayPwdActivity.this))
//                .params("idcard", showHao.getText().toString().trim())
//                .execute(new StringCallback() {
//                    @Override
//                    public void onSuccess(String s, Call call, Response response) {
//                        Log.e("sdsfdsferdadsyanzheng", s + "");
//                        try {
//                            JSONObject josn = new JSONObject(s);
//                            if (josn.getString("code").equals("1")) {
//                                startActivity(new Intent(ResetPayPwdActivity.this, PayPwdActiity.class));
//                                finish();
//                            } else {
//                                showShortCenter(ResetPayPwdActivity.this, josn.getString("msg"));
//                            }
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//                    }
//                });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }

}
